/*
 * ConsoleOutputHandler.java
 *
 * Created on den 24 oktober 2007, 10:00
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package grex;

/**
 *
 * @author RIK
 */
public class ConsoleOutputHandler implements ErrorHandler,EvolutionListener,SimplificationListener{
    
    /** Creates a new instance of ConsoleOutputHandler */
    public ConsoleOutputHandler() {
    }

    public void onError(Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
    
    public void evolutionStarted(EvolutionProcess source) {
        System.out.println("\nCreating initial population ........\n");
    }
        
    public void generationTerminated(EvolutionProcess source) {
        System.out.println("\n<----------Generation: " + source.getCurrentGeneration() + "--" + "Percistence#: " + source.getPersistence() + "-------->");
        System.out.println("Average fitness: " +  source.getAverageFitness());
        System.out.println("Average length: " + source.getAverageLength());
        System.out.println( source.getBestGP().getStatisticsAsString());
        System.out.println( source.getBestGP());
    }
    public void batchTerminated(EvolutionProcess source){
        
    }
    public void evolutionTerminated(EvolutionProcess source) {
        System.out.println("<-----------------Best GP --------------------->\n"); 
        System.out.println( source.getBestGpFromBatch().getStatisticsAsString() + "\n");
        System.out.println( source.getBestGpFromBatch().getFormatedTree());
    }

    public void simplificationStarted(Simplyfier source) {
        System.out.println("\nSimplification started, creating initial population ........\n");
    }
    public void simplificationGenerationTerminated(Simplyfier source) {
     
        System.out.println("<----------Simplification generations: " + (source.getCurrentGeneration()) + "---------->");
        System.out.println(source.getSimplyfiedGP());
    }

    public void simplifictionTerminated(Simplyfier source) {
        System.out.println("<----------Simplified GP: ---------->");
        System.out.println(source.getSimplyfiedGP().getStatisticsAsString());
        System.out.println(source.getSimplyfiedGP().getFormatedTree());
    }
    public void evolutionProcessTerminated(EvolutionProcess source){
        
    }



    

    
}
